package zj.it.bhne.gridengineeringsurvey.fragment.details;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.List;

import zj.it.bhne.gridengineeringsurvey.myutils.greendao.PointsDao;
import zj.it.bhne.gridengineeringsurvey.R;
import zj.it.bhne.gridengineeringsurvey.activity.DetailsActivity;
import zj.it.bhne.gridengineeringsurvey.adapter.PoleAdapter;
import zj.it.bhne.gridengineeringsurvey.entity.greendao.Points;
import zj.it.bhne.gridengineeringsurvey.MyApplication;
import zj.it.bhne.gridengineeringsurvey.myutils.MyUtils;

/**
 * 本地項目詳情中的fragment
 */
public class PoleFragment extends Fragment {

    /**
     * 塔杆明细
     */

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_pole, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        final List<Points> pointsList = MyApplication.getInstances().getPointsDao().queryBuilder().where(PointsDao.Properties.Items_id.eq(DetailsActivity.DATA)).build().list();
        ListView pole_listView = view.findViewById(R.id.pole_listView);
        PoleAdapter poleAdapter = new PoleAdapter(pointsList, getContext());
        pole_listView.setAdapter(poleAdapter);
        pole_listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MyUtils.getToast(getContext(), "一共有" + pointsList.size() + "个点 ");
            }
        });
    }
}
